package com.theima.socket.socketdemo7;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @program: Myset
 * @description: 服务器端
 * @author: xuejingjing
 * @create: 2021-06-26 14:45
 **/
public class ServerDemo {
    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket("10000");

        //accept()方法用于等待客户端的连接
        Socket accept = serverSocket.accept();
        //一旦等待到了,就读取数据（获取输入流）
        InputStream inputStream = accept.getInputStream();
        int b;
        while( (b = inputStream.read()) !=-1){
            //
            System.out.println((char) b);
        }

        //给客户端一个回写数据(第二遍没理解出来),注意这里是字节。
        OutputStream outputStream = accept.getOutputStream();
        outputStream.write("你谁呀".getBytes());


         outputStream.close();
         inputStream.close();
         accept.close();
         serverSocket.close();

    }
}
